package com.woniuxy.usecredit.service.impl;/* *
@author author
@create 2021-11-15 12:21
*/

import com.woniuxy.entity.EnterpriseGuarantee;
import com.woniuxy.usecredit.mapper.GuaranteeMapper;
import com.woniuxy.usecredit.service.GuaranteeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GuaranteeServiceImpl implements GuaranteeService {

    @Autowired
    GuaranteeMapper guaranteeMapper;

    @Override
    public int addGuarantee(EnterpriseGuarantee enterpriseGuarantee) {
       return guaranteeMapper.insertEnterpriseGuarantee(enterpriseGuarantee);
    }

    @Override
    public List<EnterpriseGuarantee> getGuaranteeByCreditId(int creditId) {
        return guaranteeMapper.selectEnterpriseGuarantee(creditId);
    }

    @Override
    public List<EnterpriseGuarantee> getAllGuarantee() {
        return guaranteeMapper.selectAllGuarantee();
    }

    @Override
    public boolean removeGuarantee(int guaranteeId) {
        EnterpriseGuarantee guarantee = guaranteeMapper.selectGuaranteeById(guaranteeId);
        //如果担保对象已用信，将不能删除
        if(guarantee.getGuaranteeUsedAmount()>0){
            return false;
        }
        try{
            guaranteeMapper.deleteEnterpriseGuarantee(guaranteeId);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
